package com.woniu.micropropertyserver.housemag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microcommonsserver.entity.HouseChangeInfoEntity;
import com.woniu.microcommonsserver.entity.HouseInfoEntity;
import com.woniu.microcommonsserver.param.PageRequest;
import com.woniu.micropropertyserver.housemag.mapper.HouseMapper;
import com.woniu.micropropertyserver.housemag.service.IHouseService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：pengchufeng
 * @date ：Created in 2021/2/1
 * @description：房产service接口实现
 */
@Transactional(readOnly = true)
@Service
public class HouseServiceImpl implements IHouseService {

    @Resource
    private HouseMapper houseMapper;

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public PageInfo<HouseInfoEntity> findBy(PageRequest request, HouseInfoEntity houseInfoEntity) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->houseMapper.findBy(request,houseInfoEntity));
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public List<HouseChangeInfoEntity> findChange(String id) {
        return houseMapper.findChange(id);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean bind(String hid, String uid, String name,String phone) {
        houseMapper.bind(hid,uid,name,phone);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean unbind(String hid) {
        houseMapper.unbind(hid);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean cBind(String hid, String uid, String name,String phone) {
        houseMapper.cBind(hid,uid,name,phone);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean addChange(HouseChangeInfoEntity houseChangeInfoEntity) {
        houseMapper.addChange(houseChangeInfoEntity);
        return true;
    }

    @Override
    public List<HouseInfoEntity> findByCard(String cardId) {
        return houseMapper.findByOid(cardId);
    }
}
